import 'package:app_30/models/load_entity.dart';
import 'package:app_30/models/referral_entity.dart';
import 'package:app_30/net/dio_utils.dart';
import 'package:app_30/net/http_api.dart';
import 'package:app_30/res/constant.dart';
import 'package:app_30/util/cache_utils.dart';
import 'package:app_30/util/toast_utils.dart';
import 'package:flutter/widgets.dart';

class TuijianListViewModel extends ChangeNotifier {
  String title = '推荐奖励';
  LoadEntity? loadData;

  List<ReferralEntity> data = [];
  TextEditingController zhifubao = TextEditingController();
  TextEditingController zhanghao = TextEditingController();

  void initialise() {
    title = '推荐奖励';
    loadData = getLoadData();
    notifyListeners();
    searchTjMm();
  }

  // 推荐奖励
  searchTjMm() async {
    Map<String, dynamic> map = Map();
    map['user'] = "${loadData?.user}";
    map['mysqlid'] = "${loadData?.id}";
    map['type'] = Constant.tjmx;
    map['num'] = "";

    await DioUtils.instance.requestNetwork<List<ReferralEntity>>(
      Method.post,
      HttpApi.chaxun,
      params: map,
      onSuccess: (dat) {
        data = dat!;
        notifyListeners();
      },
      onError: (_, __) {
        print('$_, $__');
      },
    );
  }

  // 申请结算
  Future<void> fcEran() async {
    // 支付宝 账号 验证没写
    Map<String, dynamic> map = Map();
    map['user'] = "${loadData?.user}";
    map['mysqlid'] = "${loadData?.id}";
    map['txzh'] = zhifubao.text;
    map['txxm'] = zhanghao.text;
    map['app'] = getPlatform();
    map['time'] = "";

    await DioUtils.instance.requestNetwork<String>(
      Method.post,
      HttpApi.tjrfcget,
      params: map,
      onSuccess: (data) {
        Toast.show('${data}');
        searchTjMm();
      },
      onError: (_, __) {
        Toast.show('${__}');
      },
    );
  }
}
